package com.ylr.basic.common.exception.advice;

import com.ylr.base.common.exception.advice.BaseAdvice;
import com.ylr.base.common.tool.Result;
import com.ylr.basic.common.exception.AesException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-04-21 15:04:11
 * className: ExceptionAdvice
 * version: 1.0
 * description:
 */
@RestControllerAdvice
public class ExceptionAdvice extends BaseAdvice {

    private static final Logger log = LoggerFactory.getLogger(ExceptionAdvice.class);

    public ExceptionAdvice(RabbitTemplate rabbitTemplate) {
        super(rabbitTemplate);
    }

    /**
     * AES操作异常处理方法
     * @param request      http请求对象
     * @param aesException 异常对象
     */
    @ExceptionHandler(AesException.class)
    public Result<Object> serviceException(HttpServletRequest request, AesException aesException) {
        log.error("AES操作异常 Url: {} Type: {} message: {}", request.getRequestURI(), request.getMethod(), aesException.getMessage());
        return Result.fail();
    }
}
